package com.cblz.bd.common.core.utils;

import com.cblz.bd.common.core.constant.ResponseStatusCode;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.LinkedHashMap;

/**
 * 统一返回结果类
 */
public class ResultResponse extends LinkedHashMap<String, Object> implements Serializable {

    private static final long serialVersionUID = 1L;

    public ResultResponse message(String message) {
        this.put("code", ResponseStatusCode.SUCCESS.getStatusCode());
        this.put("msg", message);
        this.put("time", LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
        this.put("data", null);
        return this;
    }

    public ResultResponse message(Integer statusCode, String message) {
        this.put("code", statusCode);
        this.put("msg", message);
        this.put("time", LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
        this.put("data", null);
        return this;
    }

    public ResultResponse message(Integer statusCode, String message, Object data) {
        this.put("code", statusCode);
        this.put("msg", message);
        this.put("time", LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
        this.put("data", data);
        return this;
    }

    public ResultResponse data(Object data) {
        this.put("code", 1);
        this.put("msg", "");
        this.put("time", LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
        this.put("data", data);
        return this;
    }

    public ResultResponse data(String msg, Object data) {
        this.put("code", 1);
        this.put("msg", msg);
        this.put("time", LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
        this.put("data", data);
        return this;
    }

    @Override
    public ResultResponse put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public String getMessage() {
        return String.valueOf(get("message"));
    }

    public Object getData() {
        return get("data");
    }
}
